package com.atlassian.jira.rpc.soap;

import junit.framework.TestCase;

import javax.xml.namespace.QName;

import com.atlassian.jira.rpc.soap.beans.RemoteProject;
import com.atlassian.jira.rpc.soap.beans.RemoteIssue;
import com.atlassian.jira.rpc.soap.beans.RemoteFilter;

/**
 * @author Ivan Latysh
 * @version 0.1
 * @since 9-Jul-2007 : 11:18:00 PM
 */
public class JiraSoapServiceTest extends TestCase {

  final String wsdlLocation = "http://jira.ivanlatysh.dyndns.org/rpc/soap/jirasoapservice-v2?wsdl";
  final QName serviceQName = new QName("http://jira.ivanlatysh.dyndns.org/rpc/soap/jirasoapservice-v2", "JiraSoapServiceService");

  public void testSoapService() {
    try {
      // get soap service locator
      JiraSoapServiceService jiraSoapServiceGetter = new JiraSoapServiceServiceLocator(wsdlLocation, serviceQName);
      // get SOAP service
      JiraSoapService jiraSoapService = jiraSoapServiceGetter.getJirasoapserviceV2();
      // login
      String token = jiraSoapService.login("ivan", "developer");

      // get projects
      RemoteProject[] projects = jiraSoapService.getProjects(token);
      assertNotNull(projects);
      assertTrue(projects.length>0);

      // get savedFilters
      RemoteFilter[] filters = jiraSoapService.getSavedFilters(token);
      assertNotNull(filters);
      assertTrue(filters.length>0);

      // get issues for the first filter
      RemoteIssue[] issues = jiraSoapService.getIssuesFromFilter(token,filters[0].getId());
      assertNotNull(issues);
      assertTrue(issues.length>0);

    } catch (Exception e) {
      e.printStackTrace();
      fail(e.getMessage());
    }
  }
  
}
